package com.ll.domain.user.enums;

import com.ll.base.util.ScalarUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Getter
public enum RoleEnum {
    //
    立木合作方(0, 646124254L, "立木合作方", new String []{""}),
    弓箭爱好者(1, 467436763L, "弓箭爱好者", new String []{""}),
    学员(2, 467409820L, "学员", new String []{""}),
    射手(3, 467308720L, "射手", new String []{""}),
    教练(4, 467732588L, "教练", new String []{""}),
    管理员(5, 467725548L, "管理员", new String []{""});


    private Integer id;
    private Long dingTalkDeptId;
    private String roleName;
    private String[] sources;

    RoleEnum(Integer id, Long dingTalkDeptId, String roleName, String[] sources) {
        this.id = id;
        this.dingTalkDeptId = dingTalkDeptId;
        this.roleName = roleName;
        this.sources = sources;
    }

    public static List<RoleEnum> getByRole(List<Long> dingTalkDeptId) {
        Set<RoleEnum> roles = new HashSet<>();
        if(dingTalkDeptId != null){
            dingTalkDeptId.forEach(r -> {
                for (RoleEnum roleEnum : RoleEnum.values()) {
                    if (roleEnum.getDingTalkDeptId().equals(r)) {
                        roles.add(roleEnum);
                    }
                }
            });
        }

        if (roles.isEmpty()) {
            roles.add(RoleEnum.弓箭爱好者);
        }
        return new ArrayList<>(roles);
    }


    public static RoleEnum getMaxRole(List<RoleEnum> roles) {
        RoleEnum result = RoleEnum.立木合作方;
        if (ScalarUtil.isNotEmpty(roles)) {
            for (RoleEnum roleEnum : roles) {
                if (roleEnum.getId().compareTo(result.getId()) > 0) {
                    result = roleEnum;
                }
            }
            return result;
        }
        return result;
    }
}
